package com.um2.mauction.java;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class FrmLoginVisitorBean extends ActionForm 
{
	private static final long serialVersionUID = 1L;

	private String txtLog;
	private String txtPass;

	public String getTxtLog() 
	{
		return txtLog;
	}

	public void setTxtLog(String txtLog)
	{
		this.txtLog = txtLog;
	}

	public String getTxtPass() 
	{
		return txtPass;
	}

	public void setTxtPass(String txtPass) 
	{
		this.txtPass = txtPass;
	}

	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) 
	{
		ActionErrors errors = new ActionErrors();
		if (txtLog == null || txtLog.trim().equals("")) 
		{
			errors.add("LogVide", new ActionMessage(
					"login.visitor.txtLog.vide"));
		}
		if (txtPass == null || txtPass.trim().equals("")) 
		{
			errors.add("PassVide", new ActionMessage(
					"login.visitor.txtPass.vide"));
		} 
		else if (!txtLog.matches("(\\S)+@(\\S)+\\.(\\S)+")) 
			{
				errors.add("PassIncorect", new ActionMessage(
					"login.visitor.txtLog.incorrect"));
			}
		return errors;
	}
}